package com.jxgyl.test.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.jxgyl.common.data.R;
import com.jxgyl.common.util.ErrorException;
import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @program: middleplatform
 * @description:
 * @author: Wanglipeng
 * @create: 2022-01-21 10:02
 **/
@Controller
@RequestMapping(value = "/test2")
@Log4j2
public class PlateformController {

    @PostMapping(value = "gatewaytest")
    @ResponseBody
    //@SentinelResource(value = "test1",blockHandler = "blocktest",fallback = "fallbacktest2")
    public R<String> test(@RequestParam String name){
        if(name.equals("ta")){
            log.info("yichangl");
            throw new ErrorException("ces");
        }
        log.info("gatewaytest进来了="+name);
        return R.ok("OKKK");
    }

    public String blocktest(String name,BlockException b){
        log.info("ee="+b);
        return "限流的"+name;

    }

    public String fallbacktest2(String name){
        log.info("降级了");
        return "降级的"+name;

    }

}
